package net.orange.framework.validator;

import net.orange.architecture.validator.IObjectValidator;
import net.orange.framework.model.User;

/**
 * Validation : The user code should follow the special format: UXX, XXXX is
 * four digital number.
 */
public class UserCodeFormatValidator extends FrameworkValidator implements
		IObjectValidator {
	/**
	 * The target user.
	 */
	private User user;

	/**
	 * Disabled the default contractor.
	 * 
	 * @exception
	 */
	@SuppressWarnings("unused")
	private UserCodeFormatValidator() throws Exception {

	}

	/**
	 * Constructor with group object to initialize the validation.
	 * 
	 * @param group
	 *            The target group.
	 * @exception
	 */
	public UserCodeFormatValidator(User user) throws Exception {
		this.user = user;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#check()
	 */
	public boolean check() throws Exception {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.ObjectValidator#getMessage()
	 */
	public String getMessage() {
		return "";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.validator.IObjectValidator#validate()
	 */
	public String validate() throws Exception {
		if (user.getUser_code().length() != 5
				|| !user.getUser_code().startsWith("U")) {
			return message.get("error2_user_01");
		}

		String s = user.getUser_code().substring(1, 5);

		try {
			Integer.parseInt(s);
		} catch (Exception e) {
			return message.get("error2_user_01");
		}
		return null;
	}
}
